<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import financialSettle from '@/api/financial/financialSettle'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const indexid = ref(0)

const open =  (row) => {
  indexid.value = row.user_id
  crudRef.value.refresh()
}


const numberOperation = (newValue, id, numberName) => {
  financialSettle.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  financialSettle.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_financial_settle',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: financialSettle.getList,
  recycleApi: financialSettle.getRecycleList,
  add: {
    show: true,
    api: financialSettle.save,
    auth: ['financial:settle:save']
  },
  edit: {
    show: true,
    api: financialSettle.update,
    auth: ['financial:settle:update']
  },
  delete: {
    show: true,
    api: financialSettle.deletes,
    auth: ['financial:settle:delete'],
    realApi: financialSettle.realDeletes,
    realAuth: ['financial:settle:realDeletes']
  },
  recovery: {
    show: true,
    api: financialSettle.recoverys,
    auth: ['financial:settle:recovery']
  },
  import: {
    show: true,
    url: 'financial/settle/import',
    templateUrl: 'financial/settle/downloadTemplate',
    auth: ['financial:settle:import']
  },
  export: {
    show: true,
    url: 'financial/settle/export',
    auth: ['financial:settle:export']
  },
  beforeRequest: (params) => {
    params.send_dept_id = indexid.value
	},
})

const columns = reactive([
  {
    title: "结算单号",
    dataIndex: "order_no",
    formType: "input",
    search: true
  },
  {
    title: "结算类型",
    dataIndex: "type",
    formType: "select",
    search: true,
    dict: {
      data: [
        {
          label: "配送费",
          value: "1"
        },
        {
          label: "装卸费",
          value: "2"
        },
        {
          label: "铁路清算",
          value: "3"
        }
      ],
      translation: true
    }
  },
  {
    title: "税额",
    dataIndex: "tax_price",
    formType: "input",
    search: true
  },
  {
    title: "不含税金额",
    dataIndex: "no_tax_price",
    formType: "input",
    search: true
  },
  {
    title: "含税金额",
    dataIndex: "price",
    formType: "input",
    search: true
  },
  {
    title: "收款方",
    dataIndex: "send_dept_id",
    formType: "input",
    search: true
  },
  {
    title: "业务所属月份",
    dataIndex: "month",
    formType: "date",
    search: true,
    showTime: false
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
])
defineExpose({ open });
</script>
<script> export default { name: 'financial:settle' } </script>